const db=wx.cloud.database()
const swiperList = [
  `https://6a69-jia-2004-7gy5ewbi2ec368cd-1323896692.tcb.qcloud.la/1705886017970.png?sign=bbcccc39bfc0f1a9818838c31115a960&t=1731495108`,
  `https://6a69-jia-2004-7gy5ewbi2ec368cd-1323896692.tcb.qcloud.la/1705999363237.png?sign=ab2cf8f0b8a13090a645fc4c5c4475c8&t=1731495131`,
  `https://6a69-jia-2004-7gy5ewbi2ec368cd-1323896692.tcb.qcloud.la/章永军石雕.png?sign=13b0ef97553d9c5dc2998a00e2efadcf&t=1731495220`
];

Page({

  /**
   * 页面的初始数据
   */
  
  data: {
    current: 0,
    autoplay: true,
    duration: 500,
    interval: 3000,
    swiperList,
    class:"",
    jiangren1:"",
    jiangren2:"",
    jiangren3:"",
    jiangren4:"",
    jiangren5:"",
  },

  // 通过数据库获取数据
  getdata() {
    db.collection("jiangrenji")
 .where({
   class:"传统技艺"
 }).limit(6).get()
      .then(res => {
        console.log("获取数据成功", res);
        this.setData({
          jiangren1:res.data
        })
      })
      .catch(err => {
        console.log("获取数据失败", err);
      })
  },
  getdata1() {
    db.collection("jiangrenji")
 .where({
   class:"传统美术"
 }).limit(6).get()
      .then(res => {
        console.log("获取数据成功", res);
        this.setData({
          jiangren2:res.data
        })
      })
      .catch(err => {
        console.log("获取数据失败", err);
      })
  },
  getdata4() {
    db.collection("jiangrenji")
 .where({
   class:"传统体育"
 }).get()
      .then(res => {
        console.log("获取数据成功", res);
        this.setData({
          jiangren4:res.data
        })
      })
      .catch(err => {
        console.log("获取数据失败", err);
      })
  },
  getdata5() {
    db.collection("jiangrenji")
 .where({
   class:"传统曲艺"
 }).get()
      .then(res => {
        console.log("获取数据成功", res);
        this.setData({
          jiangren5:res.data
        })
      })
      .catch(err => {
        console.log("获取数据失败", err);
      })
  },
  getdata2() {
    db.collection("jiangrenji")
 .where({
   class:"传统戏剧"
 }).limit(6).get()
      .then(res => {
        console.log("获取数据成功", res);
        this.setData({
          jiangren3:res.data
        })
      })
      .catch(err => {
        console.log("获取数据失败", err);
      })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getdata()
    this.getdata1()
    this.getdata2()
    this.getdata4()
    this.getdata5()
  },
  fun(e){
    console.log(e.currentTarget.dataset.id);
    const id=e.currentTarget.dataset.id
    wx.navigateTo({
      url: '/packageA/pages/detail/detail?id='+id,
    })
  },
  onSearch() {
    wx.navigateTo({
      url: '/packageA/pages/search/search?key=' + this.data.value,
    })
    this.setData({
      value:""
    })
  },
  oninput(e) {
    // console.log(e.detail);
    this.setData({
      value: e.detail
    })
    // console.log(this.data.value);
  },

  pl:function(e){
    console.log(e)
    this.setData({
      class:"#"+e.currentTarget.dataset.class
    })
    var me = this;
    var query = wx.createSelectorQuery().in(me);
    query.selectViewport().scrollOffset()
    //#comm 跳转到指定id位置
    query.select(this.data.class).boundingClientRect();
    query.exec(function (res) {
      // console.log(res);
      var miss = res[0].scrollTop + res[1].top -150;
      wx.pageScrollTo({
        scrollTop: miss,
        duration: 300
      });
    });
},



  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  onChange(e) {
    const {
      detail: { current, source },
    } = e;
    // console.log(current, source);
  },


  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})